package com.example.gesture

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.gesture.ui.theme.JetpackComposeBasicTheme

/**
 * 点击手势
 * https://www.bilibili.com/video/BV1ob4y1a7ad?p=61&vd_source=e07cc8cc94eb22bd76722071b03cd199
 */
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            JetpackComposeBasicTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    GestureSample()
                }
            }
        }
    }

    @Composable
    fun GestureSample() {
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.Center,
            modifier = Modifier.fillMaxSize()
        ) {
            ClickableSample1()
        }
    }

    @Composable
    fun ClickableSample() {
        val count = remember {
            mutableIntStateOf(0)
        }
        Text(text = count.intValue.toString(), modifier = Modifier
            .clickable {

                count.intValue++

            }
            .padding(50.dp))
    }

    @Composable
    fun ClickableSample1() {
        val count = remember {
            mutableIntStateOf(0)
        }
        Text(
            text = count.intValue.toString(), modifier = Modifier
                .pointerInput(Unit) {
                    detectTapGestures(
                        onDoubleTap = {
                            Log.e("young_test9090909", "onDoubleTap it = ${it.x}")
                        },
                        onLongPress = {
                            Log.e("young_test9090909", "onLongPress it = ${it.x}")
                        },
                        onPress = {
                            Log.e("young_test9090909", "onPress it = ${it.x}")
                        },
                        onTap = {
                            Log.e("young_test9090909", "onTap it = ${it.x}")
                        }
                    )
                }
                .wrapContentSize()
                .background(Color.LightGray)
                .padding(horizontal = 50.dp, vertical = 40.dp)
        )
    }

}
